package com.navi.loaddata.loadService.impl.measureData;

import com.navi.loaddata.core.gpEntity.GpChipF;
import com.navi.loaddata.core.gpEntity.GpDefectF;
import com.navi.loaddata.core.gpEntity.GpGlassF;
import com.navi.loaddata.core.gpEntity.MppLayoutPnlD;
import com.navi.loaddata.core.mysqlEntity.EdaMeasureDefecttypeD;
import com.navi.loaddata.core.mysqlEntity.EtlConfDModel;
import com.navi.loaddata.core.oracleEntity.EtlChipV;
import com.navi.loaddata.core.oracleEntity.EtlDefectV;
import com.navi.loaddata.core.oracleEntity.EtlGlassV;
import com.navi.loaddata.loadService.impl.measureData.array.ProcessDefectDataServiceARRAY;
import com.navi.loaddata.loadService.impl.measureData.cell1.ProcessDefectDataServiceCELL1;
import com.navi.loaddata.loadService.impl.measureData.cell2.ProcessDefectDataServiceCELL2;
import com.navi.loaddata.loadService.impl.measureData.cell2.ProcessDefectDataServiceCELL2OfAds;
import com.navi.loaddata.loadService.impl.measureData.cf.ProcessDefectDataServiceCF;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author jay
 */
@Service
public class ProcessDefectDataService {
    @Autowired
    private ProcessDefectDataServiceARRAY processDefectDataServiceARRAY;
    @Autowired
    private ProcessDefectDataServiceCF processDefectDataServiceCF;
    @Autowired
    private ProcessDefectDataServiceCELL1 processDefectDataServiceCELL1;
    @Autowired
    private ProcessDefectDataServiceCELL2 processDefectDataServiceCELL2;
    @Autowired
    private ProcessDefectDataServiceCELL2OfAds processDefectDataServiceCELL2OfAds;

    private static final Logger logger = LoggerFactory.getLogger(ProcessDefectDataService.class);


    public List<EtlGlassV> processGlass(EtlConfDModel etlConfD, GpGlassF glass) throws Exception {
        List<EtlGlassV> etlGlassVList = new ArrayList<>();
            switch (etlConfD.getShop()) {
                case "ARRAY":
                    etlGlassVList = processDefectDataServiceARRAY.processGlass(glass);
                    break;
                case "CF":
                    etlGlassVList = processDefectDataServiceCF.processGlass(glass);
                    break;
                case "OC":
                    if ("CELL1".equals(etlConfD.getCellType())) {
                        etlGlassVList = processDefectDataServiceCELL1.processGlass(glass);
                    } else if ("CELL2".equals(etlConfD.getCellType())) {
                        if("ADS".equals(etlConfD.getOpe())){
                            etlGlassVList=processDefectDataServiceCELL2OfAds.processGlass(glass);
                        }else {
                            etlGlassVList = processDefectDataServiceCELL2.processGlass(glass);
                        }
                    }
                    break;
            }
        return etlGlassVList;
    }

    public List<EtlChipV> processPanel(EtlConfDModel etlConfD, List<GpChipF> defectPanelFList) throws Exception {
        if(null==defectPanelFList||defectPanelFList.size()==0){
            return null;
        }
        List<EtlChipV> etlChipVList = new ArrayList<>();
            switch (etlConfD.getShop()) {
                case "ARRAY":
                    etlChipVList = processDefectDataServiceARRAY.processPanel(defectPanelFList);
                    break;
                case "CF":
                    etlChipVList = processDefectDataServiceCF.processPanel(defectPanelFList);
                    break;
                case "OC":
                    if ("CELL1".equals(etlConfD.getCellType())) {
                        etlChipVList = processDefectDataServiceCELL1.processPanel(defectPanelFList);
                    }
            }
        return etlChipVList;
    }

    public List<EtlDefectV> processDefect(List<MppLayoutPnlD> layoutPnlDS, EtlConfDModel etlConfD, List<GpDefectF> gpDefectFList, Map<String, String> mOpeDList, HashMap<String, EdaMeasureDefecttypeD> defectCodeMap) throws Exception {
        if(null==gpDefectFList||gpDefectFList.size()==0){
            return null;
        }
        List<EtlDefectV> etlDefectVList = new ArrayList<>();
            switch (etlConfD.getShop()) {
                case "ARRAY":
                    etlDefectVList = processDefectDataServiceARRAY.processDefect(layoutPnlDS,gpDefectFList,mOpeDList);
                    break;
                case "CF":
                    etlDefectVList = processDefectDataServiceCF.processDefect(layoutPnlDS,gpDefectFList, mOpeDList);
                    break;
                case "OC":
                    if ("CELL1".equals(etlConfD.getCellType())) {

                        etlDefectVList = processDefectDataServiceCELL1.processDefect(layoutPnlDS,gpDefectFList,mOpeDList);
                    } else if ("CELL2".equals(etlConfD.getCellType())) {
                        if("ADS".equals(etlConfD.getOpe())){
                            etlDefectVList=processDefectDataServiceCELL2OfAds.processDefect(layoutPnlDS,gpDefectFList,mOpeDList,defectCodeMap);
                        }else {
                            etlDefectVList = processDefectDataServiceCELL2.processDefect(layoutPnlDS,gpDefectFList,mOpeDList,defectCodeMap);
                        }
                    }
                    break;
            }
        return etlDefectVList;
    }
}
